package leetcode.每日一题.双指针;

import org.junit.Test;

/**
 * @author ：zsy
 * @date ：Created 2022/12/28 6:34 PM
 * @description：
 */
public class 删除字符串两端相同字符后的最短长度 {
    @Test
    public void test() {
        System.out.println(new Solution().minimumLength("b"));
    }

    class Solution {
        public int minimumLength(String s) {
            int n = s.length();
            int l = 0;
            int r = n - 1;
            while (l < r && s.charAt(l) == s.charAt(r)) {
                char c = s.charAt(l);
                while (l <= r && c == s.charAt(l)) {
                    l++;
                }
                while (l <= r && c == s.charAt(r)) {
                    r--;
                }
            }
            return r - l + 1;
        }
    }
}
